<?php
/**
 * Created by PhpStorm.
 * User: HLG
 * Date: 2019/10/21
 * Time: 11:39
 */
namespace app\api\model;
class TreasureConfig extends BaseModel
{
    protected $table = 'yoshop_treasure_config';
    public function getProbability($number,$total_number)
    {
        //总概率
        $total = $total_number+$number;
        $probability = $number/$total*100;
        $result = rand($number,100);
        echo $result;
    }

    /**
     * 概率算法
     * @param $proArr
     * @return int|string
     */
    public function getRand($probability) {
        $result = '';
        //概率数组的总概率精度
        $proSum = array_sum($probability);
         //概率数组循环
        foreach ($probability as $key => $proCur)
        {
            $randNum = mt_rand(1, $proSum);
            if ($randNum <= $proCur) {
                $result = $key; break;
            } else {
                $proSum -= $proCur;
            }
        }
        unset ($probability);
        return $result;
    }

}